package CtrLayer;

import java.util.ArrayList;

import DBLayer.DBApartment;
import DBLayer.DBLevyRate;
import DBLayer.IFDBApartment;
import ModelLayer.Apartment;
import ModelLayer.Building;
import ModelLayer.Landlord;

public class CtrApartment {
	
	private IFDBApartment dbApartment;
	
	public CtrApartment(){
		dbApartment = DBApartment.getInstance();
	}
	
	public double getLevy(int noOfRooms, int buildingId){
		return DBLevyRate.getInstance().getLevy(noOfRooms, buildingId);
	}
	public double getRateZone(int buildingId){
		return DBLevyRate.getInstance().getRateZone(buildingId);
	}
	public double getRateRooms(int noOfRooms){
		return DBLevyRate.getInstance().getRateRooms(noOfRooms);
	}
	
	public double getRate(int noOfRooms, int buildingId){
		return getRateRooms(noOfRooms)+getRateZone(buildingId);
	}
	
	public int getPropertiesWithoutTenants(){
		return dbApartment.getPropertiesWithoutTenants();
	}
	
	public int getProperties(){
		return dbApartment.getProperties();
	}
	
	
	public int insert(int apartNo,double monthlyRent,int noOfRooms,double size, double deposit,boolean autoLevy, boolean autoRate, boolean parkingBay, int landLordId, int buildingNr){
		
		Apartment apart = new Apartment();
		apart.setApartNo(apartNo);
		apart.setMonthlyRent(monthlyRent);
		apart.setNoOfRooms(noOfRooms);
		apart.setSize(size);
		apart.setDeposit(deposit);
		apart.setAutoLevy(autoLevy);
		apart.setAutoRate(autoRate);
		apart.setParkingBay(parkingBay);
		
		Landlord landLord = new Landlord();
		landLord.setPid(landLordId);
		
		Building building = new Building();
		building.setBuidlingNr(buildingNr);
		
		apart.setLandlord(landLord);
		apart.setBuilding(building);
		
		return dbApartment.insert(apart);
	}
	
	public int insert(Apartment apart){
		return dbApartment.insert(apart);
	}
	
	
	public int update(Apartment apart){
		return dbApartment.update(apart);
	}
	
	public int update(int apartId,int apartNo,double monthlyRent,int noOfRooms,double size, double deposit,boolean autoLevy, boolean autoRate, boolean parkingBay, int landLordId, int buildingNr)
	{
		Apartment apart = new Apartment();
		apart.setApartId(apartId);
		apart.setApartNo(apartNo);
		apart.setMonthlyRent(monthlyRent);
		apart.setNoOfRooms(noOfRooms);
		apart.setSize(size);
		apart.setDeposit(deposit);
		apart.setAutoLevy(autoLevy);
		apart.setAutoRate(autoRate);
		apart.setParkingBay(parkingBay);
		
		Landlord landLord = new Landlord();
		landLord.setPid(landLordId);
		
		Building building = new Building();
		building.setBuidlingNr(buildingNr);
		
		apart.setLandlord(landLord);
		apart.setBuilding(building);
		return dbApartment.update(apart);
	}
	
	public int delete(int apartId){
		return dbApartment.delete(apartId);
	}
	
	
	public ArrayList<Apartment> getAll(){
		return dbApartment.getAll();
	}
	
	public ArrayList<Apartment> getApartmentsByLandlordId(int landId){
		return dbApartment.getApartmentsByLandlordId(landId);
	}
	
	public ArrayList<Apartment> getAll_where(String wClause){
		return dbApartment.getAll_where(wClause);
	}
	
	public ArrayList<Apartment> searchRandom(String searchF) {
		return dbApartment.searchRandom(searchF);
	}
	
	public Apartment getApartmentById(int apartId, boolean getContracts){
		return dbApartment.find(apartId, getContracts);
	}
	
	
}
